package com.hack4jp.hackearthquakes;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class PreferencesActivity extends Activity {

    private Button _buttonClearOAuth = null;   	
	
	@Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);   	
	
        initializeViews();
	}
	
    private void initializeViews() {
		setContentView(R.layout.preferences);			

		_buttonClearOAuth = (Button)findViewById(R.id.buttonClearOAuth);
    	if (_buttonClearOAuth != null)
    		_buttonClearOAuth.setOnClickListener(onClickClearOAuthListener);
    }
    
    private void showAlertDialog(String msg) {
    	AlertDialog.Builder alertDialog=new AlertDialog.Builder(PreferencesActivity.this);
        alertDialog.setMessage(msg);
        alertDialog.setPositiveButton("OK",new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,int whichButton) {
                setResult(RESULT_OK);
            }
        });
        alertDialog.create();
        alertDialog.show();
    }
	
    private View.OnClickListener onClickClearOAuthListener = new View.OnClickListener() {
    	@Override
    	public void onClick(View v) {
    		try {
				Preferences.getInstance().Clear();
				String msg = getString(R.string.clearaccount);
				showAlertDialog(msg);
			} catch (Exception e) {
				Toast.makeText(v.getContext(), e.getMessage(),Toast.LENGTH_LONG).show();
			}
    	}
    };	
}
